var register = require("./api/users/register");
var login = require('./api/users/login');
var logout = require('./api/users/logout');
var stopserver = require('./api/users/stopserver');
var changeps = require('./api/users/changepassword');
var changetimestamp = require('./api/users/changetimestamp');
var userslist = require('./api/users/userslist');

var updatadeviceinfo = require('./api/device/updatadeviceinfo');
var check = require('./api/device/check');
var search = require('./api/device/search');

var upload = require('./api/prodcutInfo/upload');
var pdelete = require('./api/prodcutInfo/delete');
var download = require('./api/prodcutInfo/download');
var update = require('./api/prodcutInfo/update');

var rupload = require('./api/receipt/upload');
var rconsume = require('./api/receipt/consume');
var rdownload = require('./api/receipt/download');
var rstatistics = require('./api/receipt/statistics');

var db = require("./db/db");

var express = require('express');
var cors = require('cors')
var app = express();
app.use(cors());

db.start();

app.get('/', function (req, res) {
    res.send('Hello World!');
});

//user
app.post('/users/register', function (req, res) {
    register.register(req,res);
});

app.post('/users/login', function (req, res) {
    login.login(req,res);
});

app.post('/users/logout', function (req, res) {
    logout.port(req,res);
});

app.post('/users/stopserver', function (req, res) {
    stopserver.port(req,res);
});

app.post('/users/changepassword', function (req, res) {
    changeps.port(req,res);
});

app.post('/users/changetimestamp', function (req, res) {
    changetimestamp.port(req,res);
});

app.post('/users/userslist', function (req, res) {
    userslist.port(req,res);
});

//device
app.post('/device/updatadeviceinfo', function (req, res) {
    updatadeviceinfo.port(req,res);
});

app.post('/device/updatadeviceinfo', function (req, res) {
    updatadeviceinfo.port(req,res);
});

app.post('/device/check', function (req, res) {
    check.port(req,res);
});

app.post('/device/search', function (req, res) {
    search.port(req,res);
});

//prodcutInfo
app.post('/productInfo/upload', function (req, res) {
    upload.port(req,res);
});

app.post('/productInfo/delete', function (req, res) {
    pdelete.port(req,res);
});

app.post('/productInfo/download', function (req, res) {
    download.port(req,res);
});

app.post('/productInfo/update', function (req, res) {
    update.port(req,res);
});

//receipt
app.post('/receipt/upload', function (req, res) {
    rupload.port(req,res);
});

app.post('/receipt/consume', function (req, res) {
    rconsume.port(req,res);
});

app.post('/receipt/download', function (req, res) {
    rdownload.port(req,res);
});

app.post('/receipt/statistics', function (req, res) {
    rstatistics.port(req,res);
});

app.listen(5050, function () {
    console.log('Example app listening on port 5050!');
});


